﻿#region COPYRIGHT© 2005-2013 Phillip Clark. All rights reserved.

// For licensing information see License.txt (MIT style licensing).

#endregion

using System.Diagnostics.Contracts;

namespace FlitBit.Parse
{
	partial class Match
	{
		/// <summary>
		/// Creates a rule matching all of the rules given.
		/// </summary>
		/// <param name="skipLength"></param>
		/// <param name="rules"></param>
		/// <returns></returns>
		public static Match MatchAll(int skipLength, params Match[] rules)
		{
			return new MultiMatchAll(skipLength, rules);
		}

		/// <summary>
		/// Creates a rule matching any of the rules given.
		/// </summary>
		/// <param name="rules"></param>
		/// <returns></returns>
		public static Match MatchAny(params Match[] rules)
		{
			return new MultiMatchAny(rules);
		}

		/// <summary>
		/// Creates a rule matching exactly the sequence given.
		/// </summary>
		/// <param name="rules"></param>
		/// <returns></returns>
		public static Match MatchExact(params Match[] rules)
		{
			Contract.Requires(rules != null, "rules must be given");
			if (rules.Length == 1)
			{
				return rules[0];
			}
			return new MultiMatchExact(rules);
		}

		/// <summary>
		/// Creates a rule matching if none of the given rules match.
		/// </summary>
		/// <param name="skipLength"></param>
		/// <param name="rules"></param>
		/// <returns></returns>
		public static Match MatchNone(int skipLength, params Match[] rules)
		{
			return new MultiMatchNone(skipLength, rules);
		}

		/// <summary>
		/// Creates a rule matching a rule repeatedly.
		/// </summary>
		/// <param name="rule"></param>
		/// <returns></returns>
		public static Match MatchRepeatedly(Match rule)
		{
			return new RepeatedMatch(rule, 0);
		}

		/// <summary>
		/// Creates a rule matching a rule repeatedly.
		/// </summary>
		/// <param name="rule"></param>
		/// <param name="max"></param>
		/// <returns></returns>
		public static Match MatchRepeatedly(Match rule, int max)
		{
			return new RepeatedMatch(rule, max);
		}
	}
}